package org.hairball.analysis;

import org.hairball.graph.HairballGraph;
import org.hairball.graph.MutableGraph;
import org.objectweb.asm.tree.ClassNode;

import java.util.Set;

public class AnalysisGrapher {
    private RelationshipAnalyser analyser;

    public AnalysisGrapher(RelationshipAnalyser analyser) {
        this.analyser = analyser;
    }
    
    public HairballGraph graph(ClassNode... nodes) {
        MutableGraph graph = new MutableGraph();
        for (ClassNode node : nodes) {
            Set<Relationship> relationships = analyser.analyse(node);

            for (Relationship relationship : relationships) {
                graph.addNode(relationship.from);
                graph.addNode(relationship.to);
                graph.addEdge(relationship.from, relationship.to, relationship.type);
            }
        }
        return graph;
    }
}
